#include <stdlib.h>
#include <stdio.h>

#include "globals.h"

#include "tags.h"
#include "headers.h"

scm vm_reg_ret;
scm vm_reg_env;

scm vm_globals[VM_GLOBALS_SIZE];

scm vm_global_ref(scm idx) {
  if((0 <= idx) && (idx < VM_GLOBALS_SIZE)) {
    return vm_globals[idx];
  }
  else {
    fprintf(stderr, "global ref index out of range %ld\n", idx);
    exit(-1);
  }
}

int max_glob = 0;

void vm_set_global(scm idx, scm obj) {
  if((0 <= idx) && (idx < VM_GLOBALS_SIZE)) {
	  /*
	    if(idx > max_glob) {
	    max_glob = idx;
	    fprintf(stderr, "MAX GLOBAL %d\n", max_glob);
	    }
	  */
    vm_globals[idx] = obj;
  }
  else {
    fprintf(stderr, "set global index out of range %ld\n", idx);
    exit(-1);
  }
}

